<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Create Event</title>
    </h:head>
    <h:body>
        <ui:composition template="./templateuser.xhtml">
            <ui:define name="center">
                <h:form id="formid">
                    <p:panel header="Create Event">
                        <h:panelGrid columns="3" id="eventGrid">
                            <h:outputLabel for="name">Name:</h:outputLabel>
                            <p:inputText id="name" value="#{eventBean.name}">
                                <p:ajax update="namemsg"/>
                            </p:inputText>
                            <p:message id="namemsg" for="name" />

                            <h:outputLabel for="description">Description:</h:outputLabel>
                            <p:inputText id="description" value="#{eventBean.description}">
                                <p:ajax update="descriptionmsg"/>
                            </p:inputText>
                            <p:message id="descriptionmsg" for="description" />
                            
                            <p:outputLabel for="date" value="Date:" />
                            <p:calendar id="date" value="#{eventBean.date}" >
                                <p:ajax update="datemsg"/>
                            </p:calendar>
                            <p:message id="datemsg" for="date" />
                            
                            <p:outputLabel for="startime" value="Start time:" />
                            <p:calendar id="startime" value="#{eventBean.starttime}" pattern="HH:mm a" timeOnly="true" >
                                <p:ajax update="startimemsg"/>
                            </p:calendar>
                            <p:message id="startimemsg" for="startime" />
                            
                            <p:outputLabel for="endtime" value="End time:" />
                            <p:calendar id="endtime" value="#{eventBean.endtime}" pattern="HH:mm a" timeOnly="true"  validator="#{eventBean.validateEndTime}">
                                <p:ajax update="endtimemsg"/>
                            </p:calendar>
                            <p:message id="endtimemsg" for="endtime" />
                            
                            <h:outputLabel for="address">Address:</h:outputLabel>
                            <p:inputText id="address" value="#{eventBean.address}">
                                <p:ajax update="addressmsg"/>
                            </p:inputText>
                            <p:message id="addressmsg" for="address" />
                            
                            <p:outputLabel for="country" value="Country: " />
                            <p:selectOneMenu id="country" value="#{eventBean.country}" style="width:150px">
                                <p:ajax listener="#{eventBean.onCountryChange}" update="city" />
                                <f:selectItem itemLabel="Select Country" itemValue="" noSelectionOption="true" />
                                <f:selectItems value="#{eventBean.countries}" />
                            </p:selectOneMenu>
                            <p:message id="countrymsg" for="country" />

                            <p:outputLabel for="city" value="City: " />
                            <p:selectOneMenu id="city" value="#{eventBean.city}" style="width:150px">
                                <f:selectItem itemLabel="Select City" itemValue="" noSelectionOption="true" />
                                <f:selectItems value="#{eventBean.cities}" />
                            </p:selectOneMenu>
                            <p:message id="citymsg" for="city" />
                            
                            <p:outputLabel for="eventvisibility" value="Public event: " />
                            <p:selectBooleanCheckbox id ="eventvisibility" value="#{eventBean.visibility}">
                            </p:selectBooleanCheckbox>
                            <p:message id="eventvisibilitymsg" for="eventvisibility" />
                            
                            
                            <h:outputLabel for="type">Type:</h:outputLabel>
                            <p:selectOneRadio id="type" value="#{eventBean.type}" >
                                <p:ajax event="click" update="badpanel" listener="#{eventBean.onTypeChange()}"/>
                                <f:selectItem itemLabel="Indoor" itemValue="Indoor" />
                                <f:selectItem itemLabel="Outdoor" itemValue="Outdoor" />
                            </p:selectOneRadio>
                            <p:message id="typemsg" for="type" />
                            
                        </h:panelGrid>
                        
                        <p:outputPanel id="badpanel" >
                            <h:panelGrid columns="3" >
                                <p:outputLabel id ="badweathertext" for="badweather" value="Select bad weather:" rendered="#{eventBean.renderbadpanel}"/>
                                <p:selectManyCheckbox id="badweather" value="#{eventBean.selectedweathers}" rendered="#{eventBean.renderbadpanel}" required="true" requiredMessage="Select at least one bad weather." >
                                    <p:ajax update="badweathermsg"/>
                                    <f:selectItem itemLabel="Sunny" itemValue="SUNNY" >
                                       <p:graphicImage rendered="false" value="img/SUNNY.png" />
                                    </f:selectItem>
                                    <f:selectItem itemLabel="Cloudy" itemValue="CLOUDY" >
                                        <!--<p:graphicImage value="img/01d.png" />-->
                                    </f:selectItem>
                                    <f:selectItem itemLabel="Rainy" itemValue="RAINY" >
                                        <!--<p:graphicImage value="img/01d.png" />-->
                                    </f:selectItem>
                                    <f:selectItem itemLabel="Thunderstorm" itemValue="THUNDERSTORM" >
                                        <!--<p:graphicImage value="img/01d.png" />-->
                                    </f:selectItem>
                                    <f:selectItem itemLabel="Snowy" itemValue="SNOWY" >
                                        <!--<p:graphicImage value="img/01d.png" />-->
                                    </f:selectItem>
                                    <f:selectItem itemLabel="Foggy" itemValue="FOGGY" >
                                        <!--<p:graphicImage value="img/01d.png" />-->
                                    </f:selectItem>
                                </p:selectManyCheckbox>
                                <p:message id="badweathermsg" for="badweather" />
                            </h:panelGrid>
                        </p:outputPanel>
                        
                        <p:toolbar style="margin-top: 20px">
                            <p:toolbarGroup align="right">
                                <p:commandButton value="Create" update="eventGrid"
                                         action="#{eventBean.create()}" />
                            </p:toolbarGroup>
                        </p:toolbar>
                        
                    </p:panel>
                </h:form>
            </ui:define>
        </ui:composition>
    </h:body>
</html>
